package com.tocea.formation.tpLibraryEjb.service;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.jws.WebService;

import com.tocea.formation.tpLibraryEjb.DTO.AuthorDTO;
import com.tocea.formation.tpLibraryEjb.eao.AuthorEAO;
import com.tocea.formation.tpLibraryEjb.entities.Author;
import com.tocea.formation.tpLibraryEjb.util.AuthorConvert;

@Stateless
@LocalBean
@WebService
public class AuthorBean implements IAuthorBean {

	@EJB private AuthorEAO eao;
	
	@Override
	public AuthorDTO getAuthor(String _firstname, String _lastname){
		return AuthorConvert.convert(eao.getAuthor(_firstname, _lastname));
	}
	@Override
	public void addAuthor(AuthorDTO a) {
		eao.addAuthor(a.getFirstname(), a.getLastname(), a.getAge());
	}
	
	@Override
	public void addSimpleAuthor(String fn, String ln){
		eao.addAuthor(fn, ln, 0);
	}
	
	@Override
	public void updateAuthor(AuthorDTO a) {
		eao.updateAuthor(a.getId(), a.getFirstname(), a.getLastname(), a.getAge());
	}

	@Override
	public List<AuthorDTO> getAll(){
		return AuthorConvert.convertFromListAuthorToListDTO(eao.getAll());

	}
	@Override
	public void deleteAuthor(AuthorDTO a) {
		eao.deleteAuthor(a.getFirstname(), a.getLastname());
	}

	@Override
	public List<AuthorDTO> findByNameAuthor(String nom) {
		List<Author> lista =  eao.findAuthorByName(nom);
		return AuthorConvert.convertFromListAuthorToListDTO(lista);
	}


}
